﻿var mapCircles1 = new Array();

function drapMapCircles(sites) {
    var c = Ext.getCmp('coverageMapSmall');
    var mapSmall = c.getMap();

    for (var key in sites) {

        lat = sites[key]['lat'];
        lon = sites[key]['lon'];
        radius = sites[key]['radius'];


        // convert miles to meters
        radius *= 1609.344;


        var point = new google.maps.LatLng(lat, lon);

        mapCircles1[key] = new google.maps.Circle({
            map: mapSmall,
            center: point,
            fillColor: "#80f612",
            fillOpacity: 0.3,
            strokeColor: "#FF0000",
            strokeOpacity: 0.8,
            strokeWeight: 1,
            radius: radius
        });


    }

}

function setCustomerMarker(lat, lon) {
    var image = '/images/home.png';

    var c = Ext.getCmp('coverageMapSmall');
    var mapSmall = c.getMap();

    var point = new google.maps.LatLng(lat, lon);

    mapSmallCustMarker = new google.maps.Marker({
        position: point,
        map: mapSmall,
        title: 'Prequaled Address',
        icon: image
    });
}



function createMap(cust_lat, cust_lon, sites) {
    map = new Ext.Panel({
        width: 560,
        height: 300,
        layout: 'fit',
        renderTo: 'coverage_map',
        items: [{
            xtype: 'gmappanel',
            width: 300,
            height: 200,
            zoomLevel: 11,
            gmapType: 'map',
            id: 'coverageMapSmall',
            mapControls: [''],
            mapConfOpts: ['enableDoubleClickZoom', 'enableDragging'],
            setCenter: {
                lat: cust_lat,
                lng: cust_lon
            },
            onMapReady: function () {
                drapMapCircles(sites);
                setCustomerMarker(cust_lat, cust_lon);
            }
        }]
    });

}


